<?php

namespace App\Admin\Controllers;

use App\Services\AqModelService;
use Slowlyo\OwlAdmin\Controllers\AdminController;

/**
 * 问答模型
 *
 * @property AqModelService $service
 */
class AqModelController extends AdminController
{
	protected string $serviceName = AqModelService::class;

	public function list()
	{
		$crud = $this->baseCRUD()
			->filter($this->baseFilter()->body([
				amis()->SelectControl('enabled', '是否启用')->size('md')->clearable(1)->options([['value' => 1,'label' => '是',],['value' => 0,'label' => '否',],]),
			]))
			->headerToolbar([
				$this->createButton('dialog'),
				...$this->baseHeaderToolBar()
			])
			->columns([
                amis()->TableColumn('id', 'ID')->sortable(),
                amis()->TableColumn('displayorder', '显示顺序')->sortable(),
				amis()->TableColumn('name', '模型名称'),
				amis()->TableColumn('enabled', '是否启用')->quickEdit(['type' => 'switch','mode' => 'inline','saveImmediately' => true,]),
				amis()->TableColumn('ext_num', '消耗积分')->sortable(),
				amis()->Operation()->label(admin_trans('admin.actions'))->buttons([
					$this->rowEditButton('dialog'),
					$this->rowDeleteButton(),
				])
			]);

		return $this->baseList($crud);
	}

	public function form($isEdit = false)
	{
		return $this->baseForm()->body([
            amis()->NumberControl('displayorder', '显示顺序')->required(1)->value(0)->min(0)->max(999999)->description('越小越靠前'),
            amis()->TextControl('name', '模型名称')->required(1),
			amis()->SwitchControl('enabled', '是否启用')->value(1)->required(1),
			amis()->SelectControl('text_model', '文本模型')->value('qwen-max')->placeholder('请选择模型')->required(1)->options([
				['value' => 'qwen-max', 'label' => 'qwen-max'],
				['value' => 'qwen-plus', 'label' => 'qwen-plus'],
			]),
            amis()->TransferControl()->label('可用用户组')->name('group_ids')
                ->row('3')->selectMode('list')
                ->resultListModeFollowSelect('')->source('groups')
                ->labelField('grouptitle')->valueField('groupid')->required('1'),
            amis()->SwitchControl('doc_enabled', '文档是否启用')->value(0)->required(1),
            amis()->SwitchControl('image_enabled', '图片是否启用')->value(0)->required(1),
			amis()->TextControl('image_model', '图片模型')->required(1)->hiddenOn('!image_enabled')->labelRemark([
				'icon' => 'fa fa-question-circle',
				'trigger' => [
					'0' => 'hover',
				],
				'className' => 'Remark--warning',
				'placement' => 'top',
				'title' => '模型文档',
				'content' => 'https://help.aliyun.com/zh/model-studio/user-guide/vision/?spm=a2c4g.11186623.help-menu-2400256.d_1_0_2.74ca7d05vABzKX#7ddea59a840n1',
			]),
			amis()->TextareaControl('image_prompt', '图片解析提示词')->required(1)->hiddenOn('!image_enabled'),
			amis()->TextControl('app_id', '应用ID')->required(1),
			amis()->TextControl('api_key', 'API-KEY')->required(1),
			amis()->NumberControl('ext_num', '消耗积分')->min(0)->value(0)->required(1),
			amis()->TextControl('loading_text', '思考提示'),
			amis()->TextareaControl('prompt', '组合提示词')->required(1)->labelRemark([
				'icon' => 'fa fa-question-circle',
				'trigger' => [
					'0' => 'hover',
				],
				'className' => 'Remark--warning',
				'placement' => 'top',
				'title' => '可用变量',
				'content' => '用户输入：{prompt}<br />图片解析：{image_text}',
			]),
		]);
	}

	public function detail()
	{
		return $this->baseDetail()->body([
			amis()->TextControl('id', 'ID')->static(),
			amis()->TextControl('name', '模型名称')->static(),
			amis()->StaticExactControl('enabled', '是否启用')->type('static-status'),
			amis()->TextControl('app_id', '应用ID')->static(),
			amis()->TextControl('created_at', admin_trans('admin.created_at'))->static(),
			amis()->TextControl('updated_at', admin_trans('admin.updated_at'))->static(),
		]);
	}
}
